package com.grid.action;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import com.grid.db.ConnectMysql;
import com.grid.model.Operation;


@Path("/drilldown")
public class DrillDownResource {

private ArrayList<Operation> OperationListDrillDown = new ArrayList<Operation>();
	
	public ArrayList<Operation> getOperationListDrillDown() {
	return OperationListDrillDown;
}



public void setOperationListDrillDown(
		ArrayList<Operation> operationListDrillDown) {
	OperationListDrillDown = operationListDrillDown;
}

	@Context
	UriInfo uriInfo;
	@Context
	Request request;
	
	

Map<String,Integer> DrillNameMapping = new LinkedHashMap<String, Integer>();
	
	

	public Map<String, Integer> getDrillNameMapping() {
	return DrillNameMapping;
}



public void setDrillNameMapping(Map<String, Integer> drillNameMapping) {
	DrillNameMapping = drillNameMapping;
}

	private ArrayList<String> DrillDownNames = new ArrayList<String>();
	public ArrayList<String> getDrillDownNames() {
		return DrillDownNames;
	}



	public void setDrillDownNames(ArrayList<String> drillDownNames) {
		DrillDownNames = drillDownNames;
	}



	public ArrayList<Integer> getDrillDownvalues() {
		return DrillDownvalues;
	}



	public void setDrillDownvalues(ArrayList<Integer> drillDownvalues) {
		DrillDownvalues = drillDownvalues;
	}

	private ArrayList<Integer> DrillDownvalues = new ArrayList<Integer>();
	
	
		
	  @Path("/application/{selectedpplication}/{selectedoperation}")
	  @GET
	  @Consumes(MediaType.TEXT_PLAIN)
	  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	  public ArrayList<Operation> getOperationData(@PathParam ("selectedpplication") String ApplicationName,@PathParam ("selectedoperation") String OperationName) {
	       
		  System.out.println("yes i was calld with value" + ApplicationName + " and operationname " + OperationName);
	      java.sql.ResultSet rs;	
		  String query1 =  "select a.drilldownname,b.value from drilldownmaster a, operation_drilldown_mapping b,operationMaster c where a.iddrilldownmaster = b.drilldownid and b.operationid=c.idoperationMaster and c.operationName = '"+ OperationName +"';";
	      
	      
		  System.out.println(query1);
			
			rs = ConnectMysql.executeQuery(query1);
			try
			{
				while(rs.next())
				{
					
					Operation DrillDownOper = new Operation();
					
					DrillDownOper.setOperationName(rs.getString(1));
					DrillDownOper.setOperationValue(rs.getInt(2));
					
					//OperationNames.add(rs.getString(1));
					
					System.out.println(rs.getString(1));
					System.out.println(rs.getInt(2));
					
					OperationListDrillDown.add(DrillDownOper);
					
					//OperationNameMapping.put(rs.getString(1), rs.getInt(2));
				}
				
				
			}
			catch(SQLException ex)
			{
				System.out.println("SQL exception occured");
			}
	       
	      return OperationListDrillDown;
	                       
	  }
	  
	  
	
}
